﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utilities;
using InfoSoftGlobal;

public partial class DeliverableStatus : System.Web.UI.Page 
{
    private struct _DeliverableStatus
    {
        public string UserName;
        public int NotStarted;
        public int InProgress;
        public int Completed;
        public int Deferred;
        public int Waiting;
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        FCLiteral.Text = CreateDeliverableStatusChart();
        
    }

    public string CreateDeliverableStatusChart()
    {
        string sqlCon = System.Configuration.ConfigurationManager.ConnectionStrings["FastSharePoint"].ConnectionString;

        System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(sqlCon);
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetDeliverableStatusByUser", con);

        cmd.CommandType = System.Data.CommandType.StoredProcedure;

        con.Open();

        System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
        System.Collections.ArrayList projects = new System.Collections.ArrayList();

        while (dr.Read())
        {
            _DeliverableStatus deliverable = new _DeliverableStatus();
            deliverable.UserName = (string)dr["UserName"];
            deliverable.NotStarted = (int)dr["NotStarted"];
            deliverable.InProgress = (int)dr["InProgress"];
            deliverable.Completed = (int)dr["Completed"];
            deliverable.Deferred = (int)dr["Deferred"];
            deliverable.Waiting = (int)dr["Waiting"];

            projects.Add(deliverable);
        }

        con.Close();

        string strXML; string strXML1; string strXML2; string strXML3; string strXML4; string strXML5; string strXML6; int i;

        //strXML = "<graph caption='Breakdown of Project Status' subCaption='(into Products and Services)' xAxisName='Project' yAxisMaxValue='5' numberSuffix='%' areaBorderColor='FFFFFF' showValues='0' numVDivLines='6' palette='5'>";
        strXML = "<graph caption='Breakdown of Deliverables' subCaption='(By User)' xAxisName='Projects' yAxisMaxValue='" + projects.Count.ToString() + "' decimalPrecision='0' areaBorderColor='FFFFFF' showValues='0' numVDivLines='5' palette='5'>";
        strXML1 = "<categories>";
        strXML2 = "<dataset seriesName='Not Started' color='999999'>";
        strXML3 = "<dataset seriesName='In Progress' color='0099FF'>";
        strXML4 = "<dataset seriesName='Completed' color='006F00'>";
        strXML5 = "<dataset seriesName='Deferred' color='FF66CC'>";
        strXML6 = "<dataset seriesName='Waiting' color='FF0000'>";

        for (i = 0; i < projects.Count; i++)
        {
            _DeliverableStatus deliverable = (_DeliverableStatus)projects[i];
            strXML1 += "<category name='" + deliverable.UserName + "' />";
            strXML2 += "<set value='" + deliverable.NotStarted.ToString() + "' />";
            strXML3 += "<set value='" + deliverable.InProgress.ToString() + "' />";
            strXML4 += "<set value='" + deliverable.Completed.ToString() + "' />";
            strXML5 += "<set value='" + deliverable.Deferred.ToString() + "' />";
            strXML6 += "<set value='" + deliverable.Waiting.ToString() + "' />";
        }

        strXML1 += "</categories>";
        strXML2 += "</dataset>";
        strXML3 += "</dataset>";
        strXML4 += "</dataset>";
        strXML5 += "</dataset>";
        strXML6 += "</dataset>";


        strXML += strXML1;
        strXML += strXML2;
        strXML += strXML3;
        strXML += strXML4;
        strXML += strXML5;
        strXML += strXML6;

        strXML += "</graph>";

        //Create the chart - Column 3D Chart with data contained in strXML
        return FusionCharts.RenderChart("../FusionCharts/FCF_StackedColumn3D.swf", "", strXML, "productSales", "450", "300", false, false);


    }


}
